home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p2.arc / ZMODEM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-30  |  17.7 KB  |  352 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* FILE: zreceive.c (Opus zmodem receiver)                                  */
  3. /*                                                                          */
  4. /*                                                                          */
  5. /*               The Opus Computer-Based Conversation System                */
  6. /*       (c) Copyright 1986, Wynn Wagner III, All Rights Reserved           */
  7. /*                                                                          */
  8. /*      This implementation of Chuck Forsberg's ZMODEM protocol was         */
  9. /*              for Opus by Rick Huebner and Wynn Wagner III                */
  10. /*                                                                          */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*  This module is similar to a header used by Opus-Cbcs (1.00).  It is     */
  14. /*  provided for your information only.  You will find undefined items.     */
  15. /*                                                                          */
  16. /*  There is absolutely no guarantee that anything here will work.  If you  */
  17. /*  break this material, you own both pieces.                               */
  18. /*                                                                          */
  19. /*  USAGE:  You may use this material in any program with no obligation     */
  20. /*          as long as there is no charge for your program.  For more       */
  21. /*          information about commercial use, contact the "OPUSinfo HERE"   */
  22. /*          BBS (124/111).                                                  */
  23. /*                                                                          */
  24. /*  NOTE:   There are a couple of things the Opus implementation does that  */
  25. /*          aren't part of the original ZModem protocol.  They all deal     */
  26. /*          with WaZOO type ("ZedZap") netmail and should only show up when */
  27. /*          used under that condition.                                      */
  28. /*                                                                          */
  29. /*             * The maximum packet size can grow larger than 1k.  It is    */
  30. /*               sensitive to the baud rate.  (2400b=2048k; 9600b=8192k)    */
  31. /*             * The sender must be able to send nothing.  In other words,  */
  32. /*               the sending system must be able to initiate and terminate  */
  33. /*               a zmodem send session without having to actually send a    */
  34. /*               file.  Normally this kind of thing would never happen in   */
  35. /*               zmodem.                                                    */
  36. /*                                                                          */
  37. /*                                                                          */
  38. /*--------------------------------------------------------------------------*/
  39. /*                                                                          */
  40. /*  More than the three folks listed above were involved with this.  Vince  */
  41. /*  Perriello, for example, probably did some tweaking here and there.  As  */
  42. /*  to Who-Wrote-What, it's kinda hard to say at this point.  Chuck Fors-   */
  43. /*  berg did the hard part.  He thought up the whole thing and wrote the    */
  44. /*  original code (on which this is based).  Rick took Chuck's code and     */
  45. /*  scrubbed the Unix out of its nap.  I took Rick's code and got as much   */
  46. /*  of the "C" stinch out as I could.  <ah-hem>  Said another way... Chuck  */
  47. /*  made it; Rick made it MsDOS; and I made it fast.  So, if you have any   */
  48. /*  kind of problem with this source code, your best best is to just figure */
  49. /*  it out yourself because everybody involved in writing the code can      */
  50. /*  safely/legitimately disavow any knowledge of the particular section     */
  51. /*  causing the trouble.                                                    */
  52. /*                                                      --- Wynn Wagner III */
  53. /*                                                                          */
  54. /*--------------------------------------------------------------------------*/
  55. /*                                                                          */
  56. /*  Naming convention:  Z_???   a routine from ZModem.C                     */
  57. /*                      _Z_???  a private routine in ZModem.C               */
  58. /*                      ZS_???  a routine in ZSend.C                        */
  59. /*                      ZR_???  a routine in ZReceive.C                     */
  60. /*                                                                          */
  61. /*--------------------------------------------------------------------------*/
  62.  
  63. #include <sys\types.h>
  64. #include <sys\stat.h>
  65. #include <stdio.h>
  66. #include <fcntl.h>
  67. #include <ctype.h>
  68. #include "xfer.h"
  69.  
  70. #define flushmo() wait_for_clear()
  71.  
  72.  
  73.    
  74. /*--------------------------------------------------------------------------*/
  75. /* Routines from N_Zmodem.H ...                                             */
  76. /*--------------------------------------------------------------------------*/
  77. byte * pascal zalloc();
  78. void pascal z_message(byte *);
  79.  
  80. int  pascal Z_GetByte(int);
  81. void pascal Z_PutString(unsigned char *);
  82. void pascal Z_SendHexHeader(unsigned short,unsigned char *);
  83. int  pascal Z_GetHeader(unsigned char *);
  84. int  pascal Z_GetZDL(void);
  85. void pascal Z_PutLongIntoHeader(long);
  86. #ifndef NO_CRC_ASM            /* If using assembler version */
  87. #define Z_UpdateCRC(x,y) xcrc(y,x)
  88. unsigned short cdecl Z_UpdateCRC(unsigned short,unsigned short);
  89. #else
  90. unsigned short pascal Z_UpdateCRC(unsigned short,unsigned short);
  91. #endif
  92.  
  93.  
  94.  
  95.  
  96. #define ZPAD            '*'            /* 052 Pad character begins frames   */
  97. #define ZDLE            030            /* ^X Zmodem escape- `ala BISYNC DLE */
  98. #define ZDLEE           (ZDLE^0100)    /* Escaped ZDLE as transmitted       */
  99. #define ZBIN            'A'            /* Binary frame indicator            */
  100. #define ZHEX            'B'            /* HEX frame indicator               */
  101. #define ZBIN32          'C'            /* Binary frame with 32 bit FCS      */
  102.  
  103. /*--------------------------------------------------------------------------*/
  104. /* Frame types (see array "frametypes" in zm.c)                             */
  105. /*--------------------------------------------------------------------------*/
  106. #define ZRQINIT         0              /* Request receive init              */
  107. #define ZRINIT          1              /* Receive init                      */
  108. #define ZSINIT          2              /* Send init sequence (optional)     */
  109. #define ZACK            3              /* ACK to above                      */
  110. #define ZFILE           4              /* File name from sender             */
  111. #define ZSKIP           5              /* To sender: skip this file         */
  112. #define ZNAK            6              /* Last packet was garbled           */
  113. #define ZABORT          7              /* Abort batch transfers             */
  114. #define ZFIN            8              /* Finish session                    */
  115. #define ZRPOS           9              /* Resume transmit at this position  */
  116. #define ZDATA           10             /* Data packet(s) follow             */
  117. #define ZEOF            11             /* End of file                       */
  118. #define ZFERR           12             /* Fatal Read/Write error Detected   */
  119. #define ZCRC            13             /* Request for file CRC and response */
  120. #define ZCHALLENGE      14             /* Receiver's Challenge              */
  121. #define ZCOMPL          15             /* Request is complete               */
  122. #define ZCAN            16             /* Other end canned with CAN*5       */
  123. #define ZFREECNT        17             /* Request for free bytes on disk    */
  124. #define ZCOMMAND        18             /* Command from sending program      */
  125. #define ZSTDERR         19             /* Send following to stderr          */
  126.  
  127. /*--------------------------------------------------------------------------*/
  128. /* ZDLE sequences                                                           */
  129. /*--------------------------------------------------------------------------*/
  130. #define ZCRCE           'h'            /* CRC next/frame ends/hdr follows   */
  131. #define ZCRCG           'i'            /* CRC next/frame continues nonstop  */
  132. #define ZCRCQ           'j'            /* CRC next/frame continues/want ZACK*/
  133. #define ZCRCW           'k'            /* CRC next/ZACK expected/end of frame*/
  134. #define ZRUB0           'l'            /* Translate to rubout 0177          */
  135. #define ZRUB1           'm'            /* Translate to rubout 0377          */
  136.  
  137. /*--------------------------------------------------------------------------*/
  138. /* Z_GetZDL return values (internal)                                        */
  139. /* -1 is general error, -2 is timeout                                       */
  140. /*--------------------------------------------------------------------------*/
  141. #define GOTOR           0400           /* Octal alert! Octal alert!         */
  142. #define GOTCRCE         (ZCRCE|GOTOR)  /* ZDLE-ZCRCE received               */
  143. #define GOTCRCG         (ZCRCG|GOTOR)  /* ZDLE-ZCRCG received               */
  144. #define GOTCRCQ         (ZCRCQ|GOTOR)  /* ZDLE-ZCRCQ received               */
  145. #define GOTCRCW         (ZCRCW|GOTOR)  /* ZDLE-ZCRCW received               */
  146. #define GOTCAN          (GOTOR|030)    /* CAN*5 seen                        */
  147.  
  148. /*--------------------------------------------------------------------------*/
  149. /* Byte positions within header array                                       */
  150. /*--------------------------------------------------------------------------*/
  151. #define ZF0             3              /* First flags byte                  */
  152. #define ZF1             2
  153. #define ZF2             1
  154. #define ZF3             0
  155. #define ZP0             0              /* Low order 8 bits of position      */
  156. #define ZP1             1
  157. #define ZP2             2
  158. #define ZP3             3              /* High order 8 bits of file pos     */
  159.  
  160. /*--------------------------------------------------------------------------*/
  161. /* Bit Masks for ZRINIT flags byte ZF0                                      */
  162. /*--------------------------------------------------------------------------*/
  163. #define CANFDX          01             /* Can send and receive true FDX     */
  164. #define CANOVIO         02             /* Can receive data during disk I/O  */
  165. #define CANBRK          04             /* Can send a break signal           */
  166. #define CANCRY          010            /* Can decrypt                       */
  167. #define CANLZW          020            /* Can uncompress                    */
  168. #define CANFC32         040            /* Can use 32 bit Frame Check        */
  169.  
  170.  
  171.  
  172.  
  173.  
  174. /*--------------------------------------------------------------------------*/
  175. /* PARAMETERS FOR ZFILE FRAME...                                            */
  176. /*--------------------------------------------------------------------------*/
  177.  
  178. /*--------------------------------------------------------------------------*/
  179. /* Conversion options one of these in ZF0                                   */
  180. /*--------------------------------------------------------------------------*/
  181. #define ZCBIN           1              /* Binary transfer - no conversion   */
  182. #define ZCNL            2              /* Convert NL to local EOLN          */
  183. #define ZCRESUM         3              /* Resume interrupted file transfer  */
  184.  
  185. /*--------------------------------------------------------------------------*/
  186. /* Management options, one of these in ZF1                                  */
  187. /*--------------------------------------------------------------------------*/
  188. #define ZMNEW           1              /* Transfer iff source newer/longer  */
  189. #define ZMCRC           2              /* Transfer if different CRC/length  */
  190. #define ZMAPND          3              /* Append contents to existing file  */
  191. #define ZMCLOB          4              /* Replace existing file             */
  192. #define ZMSPARS         5              /* Encoding for sparse file          */
  193. #define ZMDIFF          6              /* Transfer if dates/lengths differ  */
  194. #define ZMPROT          7              /* Protect destination file          */
  195.  
  196. /*--------------------------------------------------------------------------*/
  197. /* Transport options, one of these in ZF2                                   */
  198. /*--------------------------------------------------------------------------*/
  199. #define ZTLZW           1              /* Lempel-Ziv compression            */
  200. #define ZTCRYPT         2              /* Encryption                        */
  201. #define ZTRLE           3              /* Run Length encoding               */
  202.  
  203. /*--------------------------------------------------------------------------*/
  204. /* Parameters for ZCOMMAND frame ZF0 (otherwise 0)                          */
  205. /*--------------------------------------------------------------------------*/
  206. #define ZCACK1          1              /* Acknowledge, then do command      */
  207.  
  208.  
  209.  
  210.  
  211.  
  212. /*--------------------------------------------------------------------------*/
  213. /* Miscellaneous definitions                                                */
  214. /*--------------------------------------------------------------------------*/
  215. #define OK              0
  216. #define ERROR           (-1)
  217. #define TIMEOUT         (-2)
  218. #define RCDO            (-3)
  219. #define FUBAR           (-4)
  220.  
  221. #define XON             ('Q'&037)
  222. #define XOFF            ('S'&037)
  223. #define CPMEOF          ('Z'&037)
  224.  
  225. #define RXBINARY        FALSE          /* Force binary mode uploads?        */
  226. #define RXASCII         FALSE          /* Force ASCII mode uploads?         */
  227. #define LZCONV          0              /* Default ZMODEM conversion mode    */
  228. #define LZMANAG         0              /* Default ZMODEM file mode          */
  229. #define LZTRANS         0              /* Default ZMODEM transport mode     */
  230. #define PATHLEN         128            /* Max legal MS-DOS path size?       */
  231. #define KSIZE           1024           /* Max packet size (non-WaZOO)       */
  232. #define WAZOOMAX        8192           /* Max packet size (WaZOO)           */
  233. #define SECSPERDAY      (24L*60L*60L)  /* Number of seconds in one day      */
  234.  
  235.  
  236.  
  237. /*--------------------------------------------------------------------------*/
  238. /* Status and error words                                                   */
  239. /*--------------------------------------------------------------------------*/
  240. extern char  *EOT_msg;
  241. extern char  *ACK_msg;
  242. extern char  *NAK_msg;
  243. extern char  *SOH_msg;
  244. extern char  *CAN_msg;
  245. extern char  *SYN_msg;
  246. extern char  *DISK_msg;
  247. extern char  *CRC_msg;
  248. extern char  *CHK_msg;
  249. extern char  *DUPE_msg;
  250. extern char  *FUTURE_msg;
  251. extern char  *C_msg;
  252. extern char  *SHRT_msg;
  253. extern char  *TIME_msg;
  254. extern char  *SYN_msg;
  255. extern char  *INIT_msg;
  256. extern char  *FUBAR_msg;
  257. extern char  *CARRIER_msg;
  258. extern char  *NOTHING_msg;
  259. extern char  *KBD_msg;
  260. extern char  *IDUNNO_msg;
  261. extern char  *CMPL_msg;
  262. extern char  *SYNC_msg;
  263. extern char  *OPEN_msg;
  264. extern char  *WRITE_msg;
  265.  
  266. extern char  *CAN_xfer;                   /* lots of CANs then BSs          */
  267.  
  268.  
  269. /*--------------------------------------------------------------------------*/
  270. /* Parameters for calling ZMODEM routines                                   */
  271. /*--------------------------------------------------------------------------*/
  272. #define TRUE            1
  273. #define FALSE           0
  274. #define END_BATCH       (-1)
  275. #define NOTHING_TO_DO   (-2)
  276. #define DELETE_AFTER    '-'
  277. #define TRUNC_AFTER     '#'
  278. #define NOTHING_AFTER   '@'
  279. #define DO_WAZOO        TRUE
  280. #define DONT_WAZOO      FALSE
  281.  
  282.  
  283. /*--------------------------------------------------------------------------*/
  284. /* ASCII MNEMONICS                                                          */
  285. /*--------------------------------------------------------------------------*/
  286. #define NUL 0x00
  287. #define SOH 0x01
  288. #define STX 0x02
  289. #define ETX 0x03
  290. #define EOT 0x04
  291. #define ENQ 0x05
  292. #define ACK 0x06
  293. #define BEL 0x07
  294. #define BS  0x08
  295. #define HT  0x09
  296. #define LF  0x0a
  297. #define VT  0x0b
  298. #define FF  0x0c
  299. #define CR  0x0d
  300. #define SO  0x0e
  301. #define SI  0x0f
  302. #define DLE 0x10
  303. #define DC1 0x11
  304. #define DC2 0x12
  305. #define DC3 0x13
  306. #define DC4 0x14
  307. #define NAK 0x15
  308. #define SYN 0x16
  309. #define ETB 0x17
  310. #define CAN 0x18
  311. #define EM  0x19
  312. #define SUB 0x1a
  313. #define ESC 0x1b
  314. #define FS  0x1c
  315. #define GS  0x1d
  316. #define RS  0x1e
  317. #define US  0x1f
  318.  
  319.  
  320.  
  321. /*--------------------------------------------------------------------------*/
  322. /* Globals used by ZMODEM functions                                         */
  323. /*--------------------------------------------------------------------------*/
  324. extern       Rxtimeout;          /* Tenths of seconds to wait for something */
  325. extern char  Rxhdr[4];           /* Received header                         */
  326. extern char  Txhdr[4];           /* Transmitted header                      */
  327. extern long  Rxpos;              /* Received file position                  */
  328. extern byte *Filename;           /* Name of the file being up/downloaded    */
  329. extern char *Skip_msg;
  330. extern char *Cancelled_msg;
  331. extern word  z_size;
  332. extern char *UNLINK_msg;
  333.  
  334. extern int   remote_net;
  335. extern int   remote_node;
  336.  
  337. extern int   opus_maj;
  338. extern int   opus_min;
  339.  
  340.  
  341. /*--------------------------------------------------------------------------*/
  342. /* Miscellaneous routines (none are supplied with this source)              */
  343. /*--------------------------------------------------------------------------*/
  344. extern void    dosdate(int *,int *,int *);
  345. extern void    dostime(int *,int *,int *,int *);
  346.  
  347. unsigned long  freespace();
  348.  
  349.  
  350. /* END OF FILE: zmodem.h */
  351.  
  352.